<?php
require_once (dirname(__FILE__)."/api.php");
global $inc;
$files = array();
$plugins = $_SESSION['joel']->pluginslist;
$basedir = dirname(__FILE__);

// add skin file
$files['skin'] = array($_SESSION['joel']->skinpath,"styles.css");

foreach($plugins as $plugin) {
	$file = "plugins/".$plugin."/templates/styles.css";
	if(file_exists($basedir."/".$file)) {
		$files[$plugin] = array('plugins/'.$plugin.'/templates/','styles.css');
	}
}

if(isset($_GET['combined'])) {
	header ("content-type: text/css; charset=UTF-8");
	header ("cache-control: must-revalidate; max-age: 3600");
	header ("expires: " . gmdate ("D, d M Y H:i:s", time() + 3600) . " GMT");

	$content = "";
	foreach($files as $file) {
		$collection = file_get_contents($basedir."/".$file[0].$file[1]);
		$content .= str_replace('url(', 'url('.$file[0],$collection);
	}
	echo $content;
} else {
	if(DEV) {
		foreach($files as $file) {
			echo '	<link href="'.$file[0].$file[1].'" rel="stylesheet" type="text/css" />'."\n";
		}
	} else {
		echo '	<link href="styles.php?combined=1" rel="stylesheet" type="text/css" />'."\n";
	}
}

?>